package SMS.service;

import SMS.mapper.TeachersMapper;
import SMS.pojo.Teachers;
import SMS.vo.ITeacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {

    @Autowired
    private TeachersMapper teachersMapper;
    public int getTotalCount() {
        return teachersMapper.gettotalCount();
    }

    public List<ITeacher> getTeachers(int currentPage, int pageSize) {
        return teachersMapper.listTeachers((currentPage - 1) * pageSize, pageSize);
    }

    public int updateTeacher(Teachers teacher) {
        return teachersMapper.updateByPrimaryKeySelective(teacher);
    }

    public int deleteTeacher(Long id) {
        return teachersMapper.deleteByPrimaryKey(id);
    }

    public int addTeacher(Teachers teacher) {
        System.out.println("service:"+teacher);
        return teachersMapper.insert(teacher);
    }

    public int countByNo(String req) {
        return teachersMapper.countByTeaNo(req);
    }

    public int countByName(String req) {
        return teachersMapper.countByName(req);
    }

    public List<ITeacher> searchTeacherByName(String req, int currentPage, int pageSize) {
        return teachersMapper.searchTeacherByName(req, (currentPage - 1) * pageSize, pageSize);
    }

    public List<ITeacher> searchTeacherByNo(String req, int currentPage, int pageSize) {
        return teachersMapper.searchTeacherByNo(req, (currentPage - 1) * pageSize, pageSize);
    }
}
